import request from '@/config/axios'

// 文件信息接口
export interface FileInfo {
  name: string
  path: string
  isDirectory: boolean
  size: number
  lastModified: string
  type: string
}

// 文件管理 API
export const FileApi = {
  // 获取文件列表
  getFileList: async (path: string = ''): Promise<FileInfo[]> => {
    return await request.get({ 
      url: '/agent/file/list',
      params: { path }
    })
  },

  // 删除文件
  deleteFile: async (path: string): Promise<string> => {
    return await request.delete({ 
      url: '/agent/file/delete', 
      params: { path } 
    })
  },

  // 创建文件夹
  createFolder: async (name: string, path: string = ''): Promise<string> => {
    return await request.post({
      url: '/agent/file/createFolder',
      data: { name, path }
    })
  },

  // 获取上传URL
  getUploadUrl: (): string => {
    return import.meta.env.VITE_API_BASE_PATH + '/agent/file/upload'
  },

  // 获取下载URL
  getDownloadUrl: (filename: string, path: string = ''): string => {
    const params = path ? `?path=${encodeURIComponent(path)}` : ''
    return import.meta.env.VITE_API_BASE_PATH + `/agent/file/download/${encodeURIComponent(filename)}${params}`
  }
}